# import numpy as np
import pandas as pd
# arr=np.random.randint(1,20,size=(3,3))
# df=pd.DataFrame(arr,columns=['a','b','c'])
# print(df)
# print(df.agg('sum'))
# print(df.agg(['sum','mean']))
# def rang(arr):
#     return arr.max()-arr.min()
# print(df.agg({0:'sum',1:'mean',2:rang}),axis=1)
pd.set_option('display.unicode.east_asian_width',True)
df=pd.DataFrame({'班级':['一班','一班','一班','二班','二班','二班'],
                 '姓名':['zhao1','zhao2','zhao3','zhao4','zhao5','zhao6'],
                 '语文':[81,82,83,84,85,86],
                 '数学':[80,80,80,80,80,80],
                 '英语':[80,80,80,80,80,80]})
print(df)
group1=df.groupby('班级')
print()
for i in group1:
    print(i)
print(group1.get_group('一班'))
print(group1.agg('mean',numeric_only=True))
group2=df.groupby({'语文':'总成绩','数学':'总成绩','英语':'总成绩'},axis=1)
print()
for i in group2:
    df['总成绩']=group2.agg('sum')
    print(df)